package com.silp.alertdialog;

import android.app.Activity;
import android.app.AlertDialog;
import android.app.AlertDialog.Builder;
import android.app.ProgressDialog;
import android.content.DialogInterface;
import android.content.Intent;
import android.os.Bundle;
import android.util.Log;
import android.view.View;
import android.view.View.OnClickListener;
import android.widget.Button;
import android.widget.Toast;

public class AlertdialogActivity extends Activity {
    private AlertDialog malert;
	private Button mButton3;
	private Button mButton2;
	private Button mButton1;
	private Button mButton4;

	/** Called when the activity is first created. */
    @Override
    public void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.main);
        mButton1= (Button) findViewById(R.id.btn1);
        mButton2= (Button) findViewById(R.id.btn2);
        mButton3= (Button) findViewById(R.id.btn3);
        mButton4 = (Button) findViewById(R.id.btn4);
    	final String[]items = getResources().getStringArray(R.array.arrcolor);
        
        		
       mButton1.setOnClickListener(new OnClickListener() {
		
		public void onClick(View v) {
			AlertDialog.Builder mBuilder = new Builder(AlertdialogActivity.this);
	        mBuilder.setMessage("Are you want to exit ?")
	        		.setCancelable(false);
	        mBuilder.setPositiveButton("Yes", new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					// TODO Auto-generated method stub
					Log.i("TTTH", "Yes is click");

				}
			});
	        mBuilder.setNegativeButton("No", new DialogInterface.OnClickListener() {
				
				public void onClick(DialogInterface dialog, int which) {
					Log.i("TTTH", "No is click");
					dialog.cancel();
									
				}
			});
	        malert = mBuilder.create();
	        malert.show();
	 		
		}
	});
       mButton2.setOnClickListener(new OnClickListener() {
		
		public void onClick(View arg0) {
			final String[]items = getResources().getStringArray(R.array.arrcolor);
		  
			AlertDialog.Builder mBuilder2=new Builder(AlertdialogActivity.this);
			mBuilder2.setTitle("Pick one color")
					 .setItems(items, new DialogInterface.OnClickListener() {
						
						public void onClick(DialogInterface dialog, int which) {
							
						
							// TODO Auto-generated method stub
							Toast.makeText(getApplicationContext(), items[which], Toast.LENGTH_SHORT).show();
							//Toast.makeText(getApplicationContext(), Integer.toString(which), 10).show();
							
						}
					});
			AlertDialog aler2=mBuilder2.create();
			aler2.show();
		}
	});
       mButton3.setOnClickListener(new OnClickListener() {
   		
   		public void onClick(View arg0) {
   			boolean[]  selections =  new boolean[ items.length ];
   			AlertDialog.Builder mBuilder3=new Builder(AlertdialogActivity.this);
   			mBuilder3.setTitle("Pick one color");
   			mBuilder3.setMultiChoiceItems(items, selections, new DialogInterface.OnMultiChoiceClickListener() {
   				
   				public void onClick(DialogInterface dialog, int which, boolean isChecked) {
   					Toast.makeText(getApplicationContext(), Integer.toString(which), 10).show();
   				}
   			});
   				/*	 .setSingleChoiceItems(items, -1, new DialogInterface.OnClickListener() {
   						
   						public void onClick(DialogInterface dialog, int which) {
   							
   						
   							// TODO Auto-generated method stub
   							Toast.makeText(getApplicationContext(), items[which], Toast.LENGTH_SHORT).show();
   							//Toast.makeText(getApplicationContext(), Integer.toString(which), 10).show();
   							
   						}
   					});*/
   			AlertDialog aler3=mBuilder3.create();
   			aler3.show();
   			
   		}
   	});
       mButton4.setOnClickListener(new OnClickListener() {
		
		public void onClick(View arg0) {
			 
		
			Intent mIntent = new Intent (AlertdialogActivity.this,Myprogress.class);
			startActivity(mIntent);
		};
	});
    }
}